﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DLV.Utilities;
using DLV.Library.Utilities;

namespace DLV.Data.Entities
{
    public class ScheduleController
    {
        public int InsertSchedule(ScheduleInfo info)
        {
            return SQL.InsertSchedule(info.BeginLocation, info.EndLocation, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status, info.ScheduleType);
        }
        public void UpdateSchedule(ScheduleInfo info)
        {
            info.UpdatedBy = AdminUserController.GetCurrentAdminUser().UserID;
            info.UpdatedDate = DateTime.Now;
            SQL.UpdateSchedule(info.ScheduleId, info.BeginLocation, info.EndLocation, info.UpdatedBy, info.UpdatedDate, info.Status, info.ScheduleType);
        }
        public void DeleteSchedule(ScheduleInfo info)
        {
            DeleteSchedule(info.ScheduleId);
        }
        public void DeleteSchedule(int scheduleId)
        {
            SQL.DeleteSchedule(scheduleId);
        }
        public ScheduleInfo GetSchedule(int scheduleId)
        {
            return CBO.FillObject<ScheduleInfo>(SQL.GetSchedule(scheduleId));
        }
        public List<ScheduleInfo> ListSchedule()
        {
            return CBO.FillCollection<ScheduleInfo>(SQL.ListSchedule());
        }
        public List<ScheduleInfo> ListScheduleByName(string name)
        {
            return CBO.FillCollection<ScheduleInfo>(SQL.ListScheduleByName(name));
        }
        public DataTable SelectSchedule()
        {
            return CBO.ConvertToDataTable(ListSchedule(), typeof(ScheduleInfo));
        }
        public Dictionary<object, object> ListScheduleLookup()
        {
            var schedules = ListSchedule().Where(p=>p.Status==(int)Globals.DocumentStatus.Use).OrderBy(p => p.ScheduleName);
            return schedules.ToDictionary<ScheduleInfo, object, object>(info => info.ScheduleId, info => info.ScheduleName);
        }
    }
}
